﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Animation
{
    public partial class Animation : UserControl
    {
        Timer timer;
        public Animation()
        {
            InitializeComponent();
            timer = new Timer();
            timer.Interval = 100;
            timer.Tick += MyTimer_Tick;
            timer.Enabled = true;
        }
        //定时器时间间隔
        //private int interval = 10;
        public int Interval
        {
            get
            {
                //函数执行时间间隔
                return timer.Interval;
            }
            set
            {
                if(value != timer.Interval)
                {
                    timer.Interval = value;
                }
            }
        }
        private bool start = true;
        public bool Start
        {
            get
            {
                return start;
            }
            set
            {
                start = value;
            }
        }
        //最大图片数目
        private int indexMax = 11;
        public int IndexMax
        {
            get
            {
                return indexMax;
            }
            set
            {
                indexMax = value;
            }
        }
        //当前第index图片
        int index = 0;
#region 执行图片
        private void ChangePictureBox(int i)
        {
            switch (i)
            {
                case 0:
                    pictureBox.Image = Properties.Resources._1;
                    break;
                case 1:
                    pictureBox.Image = Properties.Resources._2;
                    break;
                case 2:
                    pictureBox.Image = Properties.Resources._3;
                    break;
                case 3:
                    pictureBox.Image = Properties.Resources._4;
                    break;
                case 4:
                    pictureBox.Image = Properties.Resources._5;
                    break;
                case 5:
                    pictureBox.Image = Properties.Resources._6;
                    break;
                case 6:
                    pictureBox.Image = Properties.Resources._7;
                    break;
                case 7:
                    pictureBox.Image = Properties.Resources._8;
                    break;
                case 8:
                    pictureBox.Image = Properties.Resources._9;
                    break;
                case 9:
                    pictureBox.Image = Properties.Resources._10;
                    break;
                case 10:
                    pictureBox.Image = Properties.Resources._11;
                    break;


            }
        }
#endregion
        private void MyTimer_Tick(object sender, EventArgs e)
        {
            //是否开始转动
            if (Start)
            {
                ChangePictureBox(index);
                if (index < indexMax)
                {
  
                    index++;
                }
                else
                {
                    index = 0;
                }

            }
  
        }
    }
}
